import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_scaffold/common/index.dart';
import 'package:oramemo/common/langs/text_key.dart';
import 'package:oramemo/common/styles/colors.dart';
import 'package:oramemo/core/controllers/device_controller.dart';
import 'package:oramemo/core/controllers/profile_controller.dart';
import 'package:oramemo/core/controllers/record_controller.dart';
import 'package:oramemo/core/controllers/transaction_controller.dart';
import 'package:oramemo/generated/assets.dart';
import 'package:oramemo/pages/first/first_view.dart';
import 'package:oramemo/pages/personal_center/personal_center_view.dart';
import 'package:oramemo/pages/position/position_flutter_map_view.dart';
import 'package:oramemo/pages/second/second_view.dart';

import '../transcription/ai_transcription/ai_transcription_view.dart';
import 'custom_bottom_bar.dart';
import 'home_logic.dart';

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    _putController();
    return GetBuilder<HomeLogic>(
      init: HomeLogic(),
      builder: (controller) {
        return DoublePressBackWidget(
            child: Scaffold(
          extendBody: false,
          resizeToAvoidBottomInset: false,
          bottomNavigationBar: CustomBottomBar(
            unselectedItemColor: Colours.text_gray,
            selectedItemColor: Colours.app_main,
            iconSize: 26,
            selectedFontSize: 14,
            unselectedFontSize: 14,
            items: [
              BottomNavigationBarItem(
                icon: const ItemIcon(Assets.homeFacility),
                activeIcon: const ItemIcon(Assets.homeFacilityActivate),
                label: TextKey.navFacility.tr,
              ),
              BottomNavigationBarItem(
                icon: const ItemIcon(Assets.homeLive),
                activeIcon: const ItemIcon(Assets.homeLiveActivate),
                label: TextKey.navTransliteration.tr,
              ),
              BottomNavigationBarItem(
                icon: const ItemIcon(Assets.homePosition),
                activeIcon: const ItemIcon(Assets.homePositionActivate),
                label: TextKey.navDeviceLocation.tr,
              ),
              BottomNavigationBarItem(
                icon: const ItemIcon(Assets.homePersonal),
                activeIcon: const ItemIcon(Assets.homePersonalActivate),
                label: TextKey.navPersonal.tr,
              ),
            ],
            type: BottomNavigationBarType.fixed,
            currentIndex: controller.pageIndex,
            onTap: (index) {
              controller.pageIndex = index;
              controller.update();
            },
          ),
          body: Container(
            width: Get.width,
            height: Get.height,
            decoration: const BoxDecoration(
              gradient: LinearGradient(
                begin: Alignment.topLeft,
                end: Alignment.bottomRight,
                colors: [
                  Color(0XFFC4DDFA),
                  Color(0XFFCFF3EF),
                ],
              ),
            ),
            child: Container(
              width: Get.width,
              height: Get.height,
              decoration: const BoxDecoration(
                gradient: LinearGradient(
                  begin: Alignment.topCenter,
                  end: Alignment.bottomCenter,
                  colors: [
                    Color(0X00FFFFFF),
                    Color(0XFFF3F6F9),
                    Color(0XFFF3F6F9),
                  ],
                ),
              ),
              child: IndexedStack(
                index: controller.pageIndex,
                children: const [
                  // FacilityPage(),
                  // AiTranscriptionPage(),
                  FirstPage(),
                  SecondPage(),
                  // Center(child: Text('COMING SOON')),
                  Center(child: Text('COMING SOON')),
                  // PositionPage(),
                  // PositionFlutterMapView(),
                  PersonalCenterPage()
                ],
              ),
            ),
          ),
        ));
      },
    );
  }

  void _putController() {
    Get.put(DeviceController());
    Get.put(RecordController());
    Get.put(TransactionController());
    Get.put(ProfileController());
  }
}

class ItemIcon extends StatelessWidget {
  final String assetPath;

  const ItemIcon(this.assetPath, {super.key});

  @override
  Widget build(BuildContext context) {
    return IconX.image(
      assetPath,
      size: 26,
    );
  }
}
